/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package project;

import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 *
 * @author jon
 */
public class Employee {
    private int employee_number = 0;
    private int employee_zipcode;
    private String employee_state;
    private String employee_city;
    private String employee_street;
    private String employee_name;
    private double employee_salary;
    private String employee_position;
    private Date employee_dob;
    private String employee_gender;
    private int branch_number;
    private int manager_number;

    public Employee(int branch_number, int employee_zipcode, String employee_state, String employee_city, String employee_street, String employee_name, 
            double employee_salary, String employee_position, Date employee_dob, String employee_gender, int manager_number) {
        this.branch_number = branch_number;
        this.employee_zipcode = employee_zipcode;
        this.employee_state = employee_state;
        this.employee_city = employee_city;
        this.employee_street = employee_street;
        this.employee_name = employee_name;
        this.employee_salary = employee_salary;
        this.employee_position = employee_position;
        this.employee_dob = employee_dob;
        this.employee_gender = employee_gender;
        this.manager_number = manager_number;
    }


    /**
     * @return the employee_number
     */
    public int getEmployee_number() {
        return employee_number;
    }

    /**
     * @param employee_number the employee_number to set
     */
    public void setEmployee_number(int employee_number) {
        this.employee_number = employee_number;
    }

    /**
     * @return the employee_zipcode
     */
    public int getEmployee_zipcode() {
        return employee_zipcode;
    }

    /**
     * @param employee_zipcode the employee_zipcode to set
     */
    public void setEmployee_zipcode(int employee_zipcode) {
        this.employee_zipcode = employee_zipcode;
    }

    /**
     * @return the employee_state
     */
    public String getEmployee_state() {
        return employee_state;
    }

    /**
     * @param employee_state the employee_state to set
     */
    public void setEmployee_state(String employee_state) {
        this.employee_state = employee_state;
    }

    /**
     * @return the employee_city
     */
    public String getEmployee_city() {
        return employee_city;
    }

    /**
     * @param employee_city the employee_city to set
     */
    public void setEmployee_city(String employee_city) {
        this.employee_city = employee_city;
    }

    /**
     * @return the employee_street
     */
    public String getEmployee_street() {
        return employee_street;
    }

    /**
     * @param employee_street the employee_street to set
     */
    public void setEmployee_street(String employee_street) {
        this.employee_street = employee_street;
    }

    /**
     * @return the employee_name
     */
    public String getEmployee_name() {
        return employee_name;
    }

    /**
     * @param employee_name the employee_name to set
     */
    public void setEmployee_name(String employee_name) {
        this.employee_name = employee_name;
    }

    /**
     * @return the employee_salary
     */
    public double getEmployee_salary() {
        return employee_salary;
    }

    /**
     * @param employee_salary the employee_salary to set
     */
    public void setEmployee_salary(double employee_salary) {
        this.employee_salary = employee_salary;
    }

    /**
     * @return the employee_position
     */
    public String getEmployee_position() {
        return employee_position;
    }

    /**
     * @param employee_position the employee_position to set
     */
    public void setEmployee_position(String employee_position) {
        this.employee_position = employee_position;
    }

    /**
     * @return the employee_dob
     */
    public Date getEmployee_dob() {
        return employee_dob;
    }

    /**
     * @param employee_dob the employee_dob to set
     */
    public void setEmployee_dob(Date employee_dob) {
        this.employee_dob = employee_dob;
    }

    /**
     * @return the employee_gender
     */
    public String getEmployee_gender() {
        return employee_gender;
    }

    /**
     * @param employee_gender the employee_gender to set
     */
    public void setEmployee_gender(String employee_gender) {
        this.employee_gender = employee_gender;
    }
    

    public void insert()
    {
        try
        {
            String host = "jdbc:oracle:thin:@localhost:1521:xe";
            String username = "jon";
            String password = "chaosecco";
            String driverName = "oracle.jdbc.driver.OracleDriver";
            Class.forName(driverName);

            Connection connection = DriverManager.getConnection(host,
                    username, password);
            System.out.print("Connected successfully.");
            String insertQuery = "INSERT INTO EMPLOYEE(" +
                    "employee_number, " +
                    "branch_number, " +
                    "employee_zipcode, " +
                    "employee_state, " +
                    "employee_city, " +
                    "employee_street, " +
                    "employee_name, "  +
                    "employee_salary, " +
                    "employee_position, " +
                    "employee_dob, " +
                    "employee_gender, " +
                    "manager_number)" +
                    "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
            PreparedStatement ps = connection.prepareStatement(insertQuery);
            ps.setInt(1, employee_number);
            ps.setInt(2, branch_number);
            ps.setInt(3, employee_zipcode);
            ps.setString(4, employee_state);
            ps.setString(5, employee_city);
            ps.setString(6, employee_street);
            ps.setString(7, employee_name);
            ps.setDouble(8, employee_salary);
            ps.setString(9, employee_position);
            ps.setDate(10, employee_dob);
            ps.setString(11, employee_gender);
            ps.setInt(12, manager_number);
            System.out.println("Before execute update");
            ps.executeUpdate();

            connection.close();
        }

        catch (SQLException e)
        {
            System.out.println("ERROR: " + e.getMessage());
        }

        catch(ClassNotFoundException e)
        {
            System.out.println("ERROR: " + e.getMessage());
        }
    }

    /**
     * @return the branch_number
     */
    public int getBranch_number() {
        return branch_number;
    }

    /**
     * @param branch_number the branch_number to set
     */
    public void setBranch_number(int branch_number) {
        this.branch_number = branch_number;
    }

    /**
     * @return the manager_number
     */
    public int getManager_number() {
        return manager_number;
    }

    /**
     * @param manager_number the manager_number to set
     */
    public void setManager_number(int manager_number) {
        this.manager_number = manager_number;
    }
}
